"use strict";
const e = require("../../common/vendor.js"),
  a = require("../../api/request.js"),
  t = {
    __name: "companion",
    setup(t) {
      const n = e.ref([]),
        i = e.ref([]),
        u = e.ref(!1),
        c = e.ref(["全部", "本月出发", "下月出发", "我的活动"]),
        o = e.ref(0),
        l = e.ref([]),
        r = e.ref(0),
        s = e.ref("推荐");
      async function v(a) {
        const t = a.currentTarget.dataset.index;
        o.value = l.value[t].left - e.index.getSystemInfoSync().windowWidth / 2 + l.value[t].width / 2, r.value = t, s.value = n.value[t].city
      }
      e.onMounted((async () => {
        const t = await a.requestApi("/companion_city");
        n.value = t.data;
        const c = await a.requestApi("/companion_query", {
          city: "推荐",
          keyword: "全部",
          page: 1
        });
        u.value = !(c.data.length > 0), i.value = c.data, console.log(c), await e.nextTick$1(), e.index.createSelectorQuery().selectAll(".tab").boundingClientRect((e => {
          l.value = e.map(((e, a) => ({
            width: e.width,
            left: e.left
          })))
        })).exec()
      }));
      const d = e.ref(0),
        p = e.ref("全部");
      e.watch([p, s], (async (e, t) => {
        f.value = 1;
        const n = await a.requestApi("/companion_query", {
          city: s.value,
          keyword: p.value,
          page: 1
        });
        u.value = !(n.data.length > 0), i.value = n.data
      }));
      const f = e.ref(1);

      function y() {
        e.wx$1.navigateTo({
          url: "/pages/companion/Init-partner"
        })
      }
      return e.onReachBottom((async () => {
        f.value++;
        const e = await a.requestApi("/companion_query", {
          city: s.value,
          keyword: p.value,
          page: f.value
        });
        i.value = [...i.value, ...e.data]
      })), (t, l) => e.e({
        a: e.f(n.value, ((a, t, n) => ({
          a: e.t(a.city),
          b: r.value === t ? 1 : "",
          c: r.value === t ? 1 : "",
          d: t,
          e: t,
          f: e.o(v, t)
        }))),
        b: o.value,
        c: e.f(c.value, ((t, n, i) => ({
          a: e.t(t),
          b: n,
          c: e.o((i => async function (t, n) {
            3 != n ? (d.value = n, p.value = t) : (await a.requestApi("/check_login"), e.wx$1.navigateTo({
              url: "/pages/companion/my-activities"
            }))
          }(t, n)), n),
          d: e.n(n == d.value ? "selectstyle" : "")
        }))),
        d: e.f(i.value, ((t, n, i) => ({
          a: t.author_data[0].avatarUrl,
          b: e.t(t.author_data[0].nickname),
          c: e.t(t.timestamp),
          d: e.t(t.description),
          e: e.t(t.companion_time),
          f: e.t(t.city),
          g: e.t(t.full_address),
          h: e.f(t.image, ((a, n, i) => ({
            a: n,
            b: a,
            c: e.o((n => function (a, t) {
              e.wx$1.previewImage({
                current: t,
                urls: a
              })
            }(t.image, a)), n)
          }))),
          i: e.t(t.signups),
          j: n,
          k: e.o((n => async function (t) {
            await a.requestApi("/check_login"), e.wx$1.navigateTo({
              url: "/pages/companion/partner-details?_id=" + t
            })
          }(t._id)), n)
        }))),
        e: u.value
      }, (u.value, {}), {
        f: e.o(y)
      })
    }
  };
wx.createPage(t);